package com.xintai.approval.controller;

import com.xintai.approval.domain.*;
import com.xintai.approval.service.*;
import com.xintai.common.core.controller.BaseController;
import com.xintai.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/approval/flow")
public class FlowNodeConfigController extends BaseController {

    @Autowired
    private EmployeeService employeeService;

    @Autowired
    private RolesService rolesService;

    @Autowired
    private NodeConfigService nodeConfigService;

    @Autowired
    private SelectConditionService selectConditionService;


    /**
     * 获取流程
     * @param flowBasicinfo
     * @return
     */
   @PostMapping("/getFlow")
    public FlowBasicinfo selectNodeConfig(@RequestBody FlowBasicinfo flowBasicinfo){
       return nodeConfigService.selectNodeConfig(flowBasicinfo);
    }

    /**
     * 增加流程
     * @param flowBasicinfo
     */
    @PostMapping("/add")
    public AjaxResult insertNodeConfig(@RequestBody FlowBasicinfo flowBasicinfo){
        nodeConfigService.insertNodeConfig(flowBasicinfo);
        return AjaxResult.success();
    }

    /**
     * 员工
     * @param employee
     * @return
     */
    @GetMapping("/employees")
    public Map<String, Object> findEmployees(Employees employee){
        HashMap<String, Object> map = new HashMap<>();
        List<Employees> employees =employeeService.selectEmployees(employee);
        map.put("employees",employees);
        return map;
    }

    /**
     * 角色
     * @param roles
     * @return
     */
    @GetMapping("/roles")
    public Map<String, Object> findRoles(Roles roles){
        HashMap<String, Object> map = new HashMap<>();
        List<Roles> role = rolesService.selectRoles(roles);
        map.put("roles",role);
        return map;
    }

    /**
     * 条件
     * @return
     */
    @GetMapping("/selectCondition")
    public List<SelectCondition> findCondition(){
        return selectConditionService.selectCondition();
    }


}
